fix(nextjs): add runtime error for auth() misimport from main entry point#8487
fix(nextjs): add runtime error for auth() misimport from main entry point#8487alexcarpenter wants to merge 3 commits intomainfrom
Conversation
…oint When developers import `auth` from `@clerk/nextjs` instead of `@clerk/nextjs/server`, the bundler shows a generic "'auth' is not exported" error with no guidance. Replace the type-only `declare const` stub with a real runtime Proxy export that throws a clear error message pointing to the correct import path. Ref: SDK-65 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 140d334 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds a deprecation notice to the Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
!snapshot |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
| * API Routes, Server Components, Server Actions, and Middleware. | ||
| */ | ||
| export declare const auth: never; | ||
| export { auth } from './server-only-stubs'; |
There was a problem hiding this comment.
Does this approach move the error from being a build time one to being a runtime one? I'm not sure we should do that, I'd rather take a less specific error at build time than a great one at runtime or else users risk deploying bugs to production before catching the error?
I didn't think much about feasibility or where the current message was coming from when I wrote the issue. :/
There was a problem hiding this comment.
yeah, I agree the tradeoff probably isn't worth it. losing the build-time check to improve a runtime error risks letting misimports ship to production for that subset of users.
wdyt about adding a @deprecated jsdoc notice? 140d334
Summary
authfrom@clerk/nextjsinstead of@clerk/nextjs/server, the bundler previously showed a generic'auth' is not exported from '@clerk/nextjs'error with no hint about the correct import pathdeclare const auth: neverstub with a real runtime Proxy that throws a descriptive error:Clerk: auth() was imported from '@clerk/nextjs'. The auth() helper is a server-side function and must be imported from '@clerk/nextjs/server'.auth()) and property access (auth.protect), so the helpful error surfaces regardless of how the developer uses the misimported bindingRef: SDK-65
Test plan
auth-misimport.test.tscovering both function call and property access scenariosimport { auth } from '@clerk/nextjs'shows the new error instead of the bundler error🤖 Generated with Claude Code